<?php
    if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    class MYAD_Model extends CI_Model{
        protected $table_name = '';
        function __construct(){
            parent::__construct();
            $this-> load->database();
        }
        // all function list database
        function listAll(){
            $query = $this->db->get($this->table_name);
            return $query->result_array();
        }
        function listId($id){
            $this->db->where('id',$id);
            $query = $this->db->get($this->table_name);
            return $query->result_array();
        }
        function listSelect($arraySlect){
            $strSelect = implode(",",$arraySlect);
            $this->db->select($strSelect);
            $query = $this->db->get($this->table_name);
            return $query->result_array();
        }
        function listWhere($arrayWhere){
            $this->db->where($arrayWhere);
            $query = $this->db->get($this->table_name);
            return $query->result_array();
        }
        function listOption($arraySelector,$arrayWherever,$Limit){
            $this->db->select($arraySelector);
            $this->db->where($arrayWherever);
            $this->db->limit($Limit);
            $query = $this->db->get($this->table_name);
            return $query->result_array();    
        }
        // end all function list database
        
        //---------------------------------------
        
        // all function insert database
        function insertData($arrayInsert){
            $this->db->insert($this->table_name,$arrayInsert);
        }
        // end all function insert databse
        
        //.......................................
        
        // all function update database
        function updateData($arrayUpdate,$id){
            $this->db->where('id',$id);
            $this->db->update($this->table_name,$arrayUpdate);
        }
        // end all function update databse
        
        //.......................................
        
        // all function delete database
        function deleteData($id){
            $this->db->where('id',$id);
            $this->db->delete($this->table_name);
        }
        // end all function delete databse 
        
        // count all item
        function count_all(){
            $query = $this->db->get($this->table_name);
            return $query->num_rows();
        }        
        // end count all item         
    }
?>